package com.dx.chat.kafka.config.service.impl;

import com.dx.chat.kafka.config.service.IKafkaProducerService;
import org.apache.kafka.common.PartitionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 生产者
 *
 * @author xufeng
 * @since 13.04.2023
 */
@Service("iKafkaProducerService")
public class KafkaProducerDataGroupServiceImpl implements IKafkaProducerService {

    @Autowired
    @Qualifier("kafkaTemplate4DataGroup")
    private KafkaTemplate<String, String> kafkaTemplate4DataGroup;

    @Override
    public void sendMessage(String topic, String message) {
        kafkaTemplate4DataGroup.send(topic, message);
    }

    @Override
    public void sendMessage(String topic, String key, String message) {
        kafkaTemplate4DataGroup.send(topic, key, message);
    }

    @Override
    public List<PartitionInfo> partitionsFor(String topic) {
        List<PartitionInfo> partitionInfos = kafkaTemplate4DataGroup.partitionsFor(topic);
        return partitionInfos;
    }
}